<?php
namespace app\admin\model;
use think\Db;
use think\Model;


class FrCarModel extends Model
{
	 public function __construct()
	{
		parent::__construct();

	}
	public function getCarList($page,$limit,$map=array(),$field='a.*',$checkType='')
	{
	    if(!empty($checkType)){
            $order[] = new \think\db\Expression('field(comm_pass,2,3,1,4,5)');
            $order[] = new \think\db\Expression('field(sail_pass,2,3,1,4,5)');
            $order[] = new \think\db\Expression('a.record_status asc,a.commerceinsurance_add desc,a.sail_time desc');
        }else{
	        $order = "a.record_status asc,a.add_time desc";
        }
        return Db::table('fr_car a')->join(['fr_driver_base'=>'b'],'a.driver_uid = b.driver_uid','LEFT')->join(['fr_driver_info'=>'f'],'a.driver_uid = f.driver_uid','LEFT')
			->join(['xm_user'=>'u'],'u.uid=a.driver_uid', 'LEFT')->join(['fr_driver_back'=>'bk'],'a.driver_uid=bk.driver_uid', 'LEFT')->page($page,$limit)->where($map)->order($order)->field($field)->select();
	}
	public function getCarInfo($car_id,$field='a.*')
	{
		return Db::table('fr_car a')
			->join(['fr_driver_base'=>'b'],'a.driver_uid = b.driver_uid','LEFT')
            ->join(['fr_driver_info'=>'e'], 'e.driver_uid = b.driver_uid', 'LEFT')
			->join(['xm_user'=>'u'],'a.driver_uid=u.uid')
			->field($field)
			->where('a.car_id='.$car_id)->field($field)->find();
	}

	public function searchCar($map,$field)
	{
		return Db::table('fr_car a')->join(['fr_driver'=>'b'],'a.driver_uid = b.driver_uid','LEFT')
			->where($map)->order('a.car_id desc')->field($field)->find();
	}
}
